<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" id="i1" placeholder="请输入0-100之间的整数">
<input type="button" value = "猜一猜" onclick="f()">
<div>结果:<span></span></div>

<script>
  //得到0-100随机整数
  let x = parseInt(Math.random() * 101);
  let a = 0;
  function f() {
    let i = document.querySelector("#i1");
    let s = document.querySelector("span")
    if (isNaN(i1.value)){
      s.innerText="输入错误!";
      return;
    }
    if(i1.value>x){
      s.innerText = "太大了!"
      a++;
    }else if(i1.value<x){
      s.innerText = "太小了!"
      a++;
    }else{
      s.innerText = "恭喜你答对了!共猜了"+a+"次."
      a=0;
      x = parseInt(Math.random() * 101);
    }
  }
</script>
</body>
</html>